From 8b475c10852930b8c6407cbbd476a5704cb98755 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 27 Feb 2018 07:50:05 -0800 Subject: [PATCH] Respect lock files in crates.io crates Currently Cargo doesn't publish lock files in crates.io crates but we'll eventually be doing so, so this changes Cargo to recognize `Cargo.lock` when it's published to crates.io as use it as the basis for resolution during `cargo install`. cc #2263 --- src/cargo/ops/resolve.rs | 2 +- tests/testsuite/install.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index a4c754c3f..f6e57621a 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -65,7 +65,7 @@ pub fn resolve_ws_precisely<'a>(ws: &Workspace<'a>, Some(resolve) } else { - None + ops::load_pkg_lockfile(ws)? }; let method = if all_features { diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index edb1dc627..89adafc33 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1011,3 +1011,36 @@ fn custom_target_dir_for_git_source() { assert_that(&paths::root().join("target/release"), existing_dir()); } + +#[test] +fn install_respects_lock_file() { + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.1.1") + .file("src/lib.rs", "not rust") + .publish(); + Package::new("foo", "0.1.0") + .dep("bar", "0.1") + .file("src/lib.rs", "") + .file("src/main.rs", " + extern crate foo; + extern crate bar; + fn main() {} + ") + .file("Cargo.lock", r#" +[[package]] +name = "bar" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "foo" +version = "0.1.0" +dependencies = [ + "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] +"#) + .publish(); + + assert_that(cargo_process("install").arg("foo"), + execs().with_status(0)); +} -- 2.30.2